package com.lzp.badminton.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lzp.badminton.model.Activity;
import com.lzp.badminton.mapper.ActivityMapper;
import com.lzp.badminton.service.IActivityService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lzp.badminton.vo.ActivityClubJoin;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author astupidcoder
 * @since 2022-02-11
 */
@Service
public class ActivityServiceImpl extends ServiceImpl<ActivityMapper, Activity> implements IActivityService {
    @Autowired
    private ActivityMapper activityMapper;

    @Override
    public Page<ActivityClubJoin> getActivityInfo(Page<ActivityClubJoin> page) {
        return page.setRecords(this.baseMapper.getActivityInfo(page));
    }

    // 获取某一条活动数据 联表查询
    @Override
    public ActivityClubJoin getActivityInfoById(int activityId) {
        ActivityClubJoin acj = activityMapper.getActivityInfoById(activityId);
        return acj;
    }

    // 获取某一条活动数据
    @Override
    public Activity getoneActivityInfoById(int activityId) {
        Map acMap = new HashMap<>();
        acMap.put("activity_id", activityId);

        List<Activity> activity = activityMapper.selectByMap(acMap);

        if (activity.size() != 0) {
            return activity.get(0);
        } else {
            return null;
        }
    }

}
